<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品管理 - 商品评价系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .sidebar {
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .sidebar .nav-link {
            color: rgba(255,255,255,0.8);
            border-radius: 10px;
            margin: 5px 0;
            transition: all 0.3s;
        }
        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            color: white;
            background: rgba(255,255,255,0.2);
        }
        .main-content {
            background: #f8f9fa;
            min-height: 100vh;
        }
        .content-card {
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
            margin-bottom: 30px;
        }
        .product-image {
            width: 60px;
            height: 60px;
            border-radius: 8px;
            object-fit: cover;
        }
        .status-badge {
            font-size: 0.8rem;
        }
        .action-buttons .btn {
            margin: 0 2px;
            padding: 5px 10px;
        }
        .search-box {
            background: white;
            border-radius: 25px;
            border: 1px solid #ddd;
            padding: 10px 20px;
        }
        .filter-section {
            background: white;
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .table-responsive {
            border-radius: 15px;
            overflow: hidden;
        }
        .table th {
            background: #f8f9fa;
            border: none;
            font-weight: 600;
        }
        .table td {
            border: none;
            vertical-align: middle;
        }
        .pagination {
            justify-content: center;
        }
        .pagination .page-link {
            border-radius: 50%;
            margin: 0 2px;
            border: none;
            color: #667eea;
        }
        .pagination .page-item.active .page-link {
            background: #667eea;
            border-color: #667eea;
        }
        .price-display {
            font-weight: bold;
            color: #e74c3c;
        }
        .stock-low {
            color: #e74c3c;
            font-weight: bold;
        }
        .stock-normal {
            color: #27ae60;
        }
        .rating-stars {
            color: #ffc107;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                <div class="position-sticky pt-3">
                    <div class="text-center mb-4">
                        <h4><i class="fas fa-tachometer-alt me-2"></i>管理后台</h4>
                        <small class="text-muted">欢迎，<span id="adminName">管理员</span></small>
                    </div>
                    
                    <ul class="nav flex-column">
<%--                        <li class="nav-item">--%>
<%--                            <a class="nav-link" href="/product-review/page/admin/dashboard">--%>
<%--                                <i class="fas fa-home me-2"></i>仪表板--%>
<%--                            </a>--%>
<%--                        </li>--%>
                        <li class="nav-item">
                            <a class="nav-link" href="/product-review/page/admin/users">
                                <i class="fas fa-users me-2"></i>用户管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="/product-review/page/admin/products">
                                <i class="fas fa-box me-2"></i>商品管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/product-review/page/admin/reviews">
                                <i class="fas fa-comments me-2"></i>评价管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/product-review/page/index">
                                <i class="fas fa-arrow-left me-2"></i>返回前台
                            </a>
                        </li>
                        <li class="nav-item mt-3">
                            <a class="nav-link" href="#" onclick="logout()">
                                <i class="fas fa-sign-out-alt me-2"></i>退出登录
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- 主内容区 -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
                <!-- 顶部导航 -->
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">商品管理</h1>
                    <div class="btn-toolbar mb-2 mb-md-0">
                        <div class="btn-group me-2">
                            <button type="button" class="btn btn-sm btn-outline-secondary" onclick="refreshProducts()">
                                <i class="fas fa-sync-alt me-1"></i>刷新
                            </button>
                        </div>
                        <div class="btn-group">
                            <button type="button" class="btn btn-sm btn-primary" onclick="showAddProductModal()">
                                <i class="fas fa-plus me-1"></i>添加商品
                            </button>
                        </div>
                    </div>
                </div>

                <!-- 筛选和搜索 -->
                <div class="filter-section">
                    <div class="row align-items-center">
                        <div class="col-md-4">
                            <div class="input-group">
                                <span class="input-group-text"><i class="fas fa-search"></i></span>
                                <input type="text" class="form-control" id="searchInput" placeholder="搜索商品名称、描述..." onkeyup="searchProducts()">
                            </div>
                        </div>
                        <div class="col-md-2">
                            <select class="form-select" id="categoryFilter" onchange="filterProducts()">
                                <option value="">全部分类</option>
                                <!-- 分类选项将通过JavaScript动态加载 -->
                            </select>
                        </div>
                        <div class="col-md-2">
                            <select class="form-select" id="statusFilter" onchange="filterProducts()">
                                <option value="">全部状态</option>
                                <option value="ACTIVE">上架</option>
                                <option value="INACTIVE">下架</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <select class="form-select" id="stockFilter" onchange="filterProducts()">
                                <option value="">全部库存</option>
                                <option value="low">库存不足</option>
                                <option value="normal">库存正常</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <button class="btn btn-outline-secondary w-100" onclick="resetFilters()">
                                <i class="fas fa-undo me-1"></i>重置
                            </button>
                        </div>
                    </div>
                </div>

                <!-- 商品列表 -->
                <div class="content-card">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <h5 class="mb-0">商品列表</h5>
                        <div class="d-flex align-items-center">
                            <span class="text-muted me-3">共 <span id="totalProducts">0</span> 个商品</span>
                            <div class="btn-group btn-group-sm" role="group">
                                <button type="button" class="btn btn-outline-primary" onclick="selectAllProducts()">
                                    全选
                                </button>
                                <button type="button" class="btn btn-outline-danger" onclick="batchDeleteProducts()">
                                    批量删除
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th width="50">
                                        <input type="checkbox" id="selectAll" onchange="toggleSelectAll()">
                                    </th>
                                    <th width="80">图片</th>
                                    <th>商品名称</th>
                                    <th>分类</th>
                                    <th>价格</th>
                                    <th>库存</th>
                                    <th>评分</th>
                                    <th>状态</th>
                                    <th>创建时间</th>
                                    <th width="200">操作</th>
                                </tr>
                            </thead>
                            <tbody id="productsTableBody">
                                <!-- 商品列表将通过JavaScript动态加载 -->
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- 分页 -->
                    <nav aria-label="商品分页">
                        <ul class="pagination" id="productsPagination">
                            <!-- 分页将通过JavaScript动态生成 -->
                        </ul>
                    </nav>
                </div>
            </main>
        </div>
    </div>

    <!-- 添加/编辑商品模态框 -->
    <div class="modal fade" id="productModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="productModalTitle">添加商品</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="productForm">
                        <input type="hidden" id="productId">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="productName" class="form-label">商品名称 *</label>
                                    <input type="text" class="form-control" id="productName" required>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="category" class="form-label">商品分类 *</label>
                                    <select class="form-select" id="category" required>
                                        <option value="">请选择分类</option>
                                        <option value="电子产品">电子产品</option>
                                        <option value="服装鞋帽">服装鞋帽</option>
                                        <option value="家居用品">家居用品</option>
                                        <option value="图书音像">图书音像</option>
                                        <option value="运动户外">运动户外</option>
                                        <option value="美妆个护">美妆个护</option>
                                        <option value="食品饮料">食品饮料</option>
                                        <option value="其他">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        
                        <div class="row">
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="price" class="form-label">商品价格 *</label>
                                    <div class="input-group">
                                        <span class="input-group-text">¥</span>
                                        <input type="number" class="form-control" id="price" step="0.01" min="0" required>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="mb-3">
                                    <label for="stock" class="form-label">库存数量 *</label>
                                    <input type="number" class="form-control" id="stock" min="0" required>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="description" class="form-label">商品描述</label>
                            <textarea class="form-control" id="description" rows="4" placeholder="请输入商品详细描述..."></textarea>
                        </div>
                        
                        <div class="mb-3">
                            <label for="imageUrl" class="form-label">商品图片URL</label>
                            <input type="url" class="form-control" id="imageUrl" placeholder="请输入图片链接">
                            <div class="form-text">请输入有效的图片链接地址</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="productStatus" class="form-label">商品状态</label>
                            <select class="form-select" id="productStatus">
                                <option value="1">上架</option>
                                <option value="0">下架</option>
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="saveProduct()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        // 全局变量
        let currentUser = null;
        let productModal = null;
        let allProducts = [];
        let filteredProducts = [];
        let currentPage = 1;
        let pageSize = 10;
        let isEditing = false;
        
        $(document).ready(function() {
            // 初始化模态框
            productModal = new bootstrap.Modal(document.getElementById('productModal'));
            
            // 检查管理员权限
            checkAdminPermission();
            
            // 加载商品列表
            loadProducts();
            
            // 加载分类选项
            loadCategories();
        });
        
        // 检查管理员权限
        function checkAdminPermission() {
            $.ajax({
                url: '/product-review/user/current',
                type: 'GET',
                success: function(result) {
                    if (result.code === 200 && result.data) {
                        currentUser = result.data;
                        if (result.data.role !== 'ADMIN') {
                            alert('您没有管理员权限');
                            window.location.href = '/product-review/page/index';
                            return;
                        }
                        $('#adminName').text(result.data.username);
                    } else {
                        alert('请先登录');
                        window.location.href = '/product-review/page/login';
                    }
                },
                error: function() {
                    alert('请先登录');
                    window.location.href = '/product-review/page/login';
                }
            });
        }
        
        // 加载商品列表
        function loadProducts() {
            $.ajax({
                url: '/product-review/product/list',
                type: 'GET',
                success: function(result) {
                    if (result.code === 200) {
                        allProducts = result.data || [];
                        filteredProducts = [...allProducts];
                        updateProductDisplay();
                    } else {
                        alert('加载商品列表失败：' + result.message);
                    }
                },
                error: function() {
                    alert('加载商品列表失败');
                }
            });
        }
        
        // 加载分类选项
        function loadCategories() {
            const categories = ['电子产品', '服装鞋帽', '家居用品', '图书音像', '运动户外', '美妆个护', '食品饮料', '其他'];
            let html = '<option value="">全部分类</option>';
            categories.forEach(category => {
                html += `<option value="${category}">${category}</option>`;
            });
            $('#categoryFilter').html(html);
        }
        
        // 更新商品显示
        function updateProductDisplay() {
            $('#totalProducts').text(filteredProducts.length);
            
            // 分页
            const totalPages = Math.ceil(filteredProducts.length / pageSize);
            const startIndex = (currentPage - 1) * pageSize;
            const endIndex = startIndex + pageSize;
            const pageProducts = filteredProducts.slice(startIndex, endIndex);
            
            // 显示商品列表
            displayProducts(pageProducts);
            
            // 显示分页
            displayPagination(totalPages);
        }
        
        // 显示商品列表
        function displayProducts(products) {
            let html = '';
            
            if (products.length === 0) {
                html = '<tr><td colspan="10" class="text-center text-muted py-4">暂无商品数据</td></tr>';
            } else {
                products.forEach(function(product) {
                    const createTime = new Date(product.createTime).toLocaleDateString();
                    const statusBadge = getStatusBadge(product.status);
                    const stockClass = product.stock < 10 ? 'stock-low' : 'stock-normal';
                    const rating = product.averageRating || 0;
                    const ratingStars = generateStars(rating);
                    
                    html += `
                        <tr>
                            <td>
                                <input type="checkbox" class="product-checkbox" value="\${product.id}">
                            </td>
                            <td>
                                <img src="\${product.imageUrl || '/product-review/static/img/default-product.jpg'}" class="product-image" alt="商品图片">
                            </td>
                            <td>
                                <div class="fw-bold">\${product.name}</div>
                                <small class="text-muted">ID: \${product.id}</small>
                            </td>
                            <td>\${product.category || '-'}</td>
                            <td><span class="price-display">¥\${product.price.toFixed(2)}</span></td>
                            <td><span class="\${stockClass}">\${product.stock}</span></td>
                            <td>
                                <div class="rating-stars">\${ratingStars}</div>
                                <small class="text-muted">\${rating.toFixed(1)}</small>
                            </td>
                            <td>\${statusBadge}</td>
                            <td>\${createTime}</td>
                            <td>
                                <div class="action-buttons">
                                    <button class="btn btn-sm btn-outline-primary" onclick="editProduct(\${product.id})" title="编辑">
                                        <i class="fas fa-edit"></i>
                                    </button>
                                    <button class="btn btn-sm btn-outline-warning" onclick="toggleProductStatus(\${product.id})" title="切换状态">
                                        <i class="fas fa-toggle-on"></i>
                                    </button>
                                    <button class="btn btn-sm btn-outline-info" onclick="viewProduct(\${product.id})" title="查看详情">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                    <button class="btn btn-sm btn-outline-danger" onclick="deleteProduct(\${product.id})" title="删除">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    `;
                });
            }
            
            $('#productsTableBody').html(html);
        }
        
        // 获取状态徽章
        function getStatusBadge(status) {
            const statusMap = {
                1: { text: '上架', className: 'bg-success' },
                0: { text: '下架', className: 'bg-secondary' }
            };
            
            const statusInfo = statusMap[status] || { text: '未知', className: 'bg-secondary' };
            return `<span class="badge \${statusInfo.className} status-badge">\${statusInfo.text}</span>`;
        }
        
        // 生成星级评分
        function generateStars(rating) {
            let stars = '';
            const fullStars = Math.floor(rating);
            const hasHalfStar = rating % 1 >= 0.5;
            console.log("rating"+rating)
            console.log("fullStars"+fullStars)
            for (let i = 0; i < fullStars; i++) {
                stars += '<i class="fas fa-star"></i>';
            }
            
            if (hasHalfStar) {
                stars += '<i class="fas fa-star-half-alt"></i>';
            }
            
            const emptyStars = 5 - fullStars - (hasHalfStar ? 1 : 0);
            for (let i = 0; i < emptyStars; i++) {
                stars += '<i class="far fa-star"></i>';
            }
            console.log("星星"+stars)
            return stars;
        }
        
        // 显示分页
        function displayPagination(totalPages) {
            let html = '';
            
            if (totalPages <= 1) {
                $('#productsPagination').html('');
                return;
            }
            
            // 上一页
            html += `
                <li class="page-item ${currentPage == 1 ? 'disabled' : ''}">
                    <a class="page-link" href="#" onclick="changePage(${currentPage - 1})">
                        <i class="fas fa-chevron-left"></i>
                    </a>
                </li>
            `;
            
            // 页码
            for (let i = 1; i <= totalPages; i++) {
                if (i === currentPage || i === 1 || i === totalPages || (i >= currentPage - 1 && i <= currentPage + 1)) {
                    html += `
                        <li class="page-item ${i == currentPage ? 'active' : ''}">
                            <a class="page-link" href="#" onclick="changePage(${i})">${i}</a>
                        </li>
                    `;
                } else if (i === currentPage - 2 || i === currentPage + 2) {
                    html += '<li class="page-item disabled"><span class="page-link">...</span></li>';
                }
            }
            
            // 下一页
            html += `
                <li class="page-item ${currentPage == totalPages ? 'disabled' : ''}">
                    <a class="page-link" href="#" onclick="changePage(${currentPage + 1})">
                        <i class="fas fa-chevron-right"></i>
                    </a>
                </li>
            `;
            
            $('#productsPagination').html(html);
        }
        
        // 切换页面
        function changePage(page) {
            const totalPages = Math.ceil(filteredProducts.length / pageSize);
            if (page >= 1 && page <= totalPages) {
                currentPage = page;
                updateProductDisplay();
            }
        }
        
        // 搜索商品
        function searchProducts() {
            const keyword = $('#searchInput').val().toLowerCase();
            const categoryFilter = $('#categoryFilter').val();
            const statusFilter = $('#statusFilter').val();
            const stockFilter = $('#stockFilter').val();
            
            filteredProducts = allProducts.filter(product => {
                const matchKeyword = !keyword || 
                    product.name.toLowerCase().includes(keyword) ||
                    (product.description && product.description.toLowerCase().includes(keyword));
                
                const matchCategory = !categoryFilter || product.category === categoryFilter;
                const matchStatus = !statusFilter || product.status === statusFilter;
                
                let matchStock = true;
                if (stockFilter === 'low') {
                    matchStock = product.stock < 10;
                } else if (stockFilter === 'normal') {
                    matchStock = product.stock >= 10;
                }
                
                return matchKeyword && matchCategory && matchStatus && matchStock;
            });
            
            currentPage = 1;
            updateProductDisplay();
        }
        
        // 筛选商品
        function filterProducts() {
            searchProducts();
        }
        
        // 重置筛选
        function resetFilters() {
            $('#searchInput').val('');
            $('#categoryFilter').val('');
            $('#statusFilter').val('');
            $('#stockFilter').val('');
            filteredProducts = [...allProducts];
            currentPage = 1;
            updateProductDisplay();
        }
        
        // 显示添加商品模态框
        function showAddProductModal() {
            isEditing = false;
            $('#productModalTitle').text('添加商品');
            $('#productForm')[0].reset();
            $('#productId').val('');
            productModal.show();
        }
        
        // 编辑商品
        function editProduct(productId) {
            const product = allProducts.find(p => p.id === productId);
            if (!product) return;
            
            isEditing = true;
            $('#productModalTitle').text('编辑商品');
            $('#productId').val(product.id);
            $('#productName').val(product.name);
            $('#category').val(product.category || '');
            $('#price').val(product.price);
            $('#stock').val(product.stock);
            $('#description').val(product.description || '');
            $('#imageUrl').val(product.imageUrl || '');
            $('#productStatus').val(product.status);
            
            productModal.show();
        }
        
        // 保存商品
        function saveProduct() {
            const productId = $('#productId').val();
            const name = $('#productName').val().trim();
            const category = $('#category').val();
            const price = parseFloat($('#price').val());
            const stock = parseInt($('#stock').val());
            const description = $('#description').val().trim();
            const imageUrl = $('#imageUrl').val().trim();
            const status = $('#productStatus').val();
            
            if (!name || !category || isNaN(price) || isNaN(stock)) {
                alert('请填写必填字段');
                return;
            }
            
            if (price < 0 || stock < 0) {
                alert('价格和库存不能为负数');
                return;
            }
            
            const productData = {
                name: name,
                category: category,
                price: price,
                stock: stock,
                description: description,
                imageUrl: imageUrl,
                status: status
            };
            
            const url = isEditing ? `/product-review/product/update/${productId}` : '/product-review/product/add';
            const method = isEditing ? 'PUT' : 'POST';
            
            $.ajax({
                url: url,
                type: method,
                contentType: 'application/json',
                data: JSON.stringify(productData),
                success: function(result) {
                    if (result.code === 200) {
                        alert(isEditing ? '商品更新成功' : '商品添加成功');
                        productModal.hide();
                        loadProducts();
                    } else {
                        alert('操作失败：' + result.message);
                    }
                },
                error: function() {
                    alert('操作失败');
                }
            });
        }
        
        // 切换商品状态
        function toggleProductStatus(productId) {
            const product = allProducts.find(p => p.id === productId);
            if (!product) return;
            
            const newStatus = product.status === 1 ? 0 : 1;
            
            $.ajax({
                url: `/product-review/product/status`,
                type: 'PUT',
                contentType: 'application/json',
                data: JSON.stringify({ productId: productId, status: newStatus }),
                success: function(result) {
                    if (result.code === 200) {
                        alert('商品状态更新成功');
                        loadProducts();
                    } else {
                        alert('状态更新失败：' + result.message);
                    }
                },
                error: function() {
                    alert('状态更新失败');
                }
            });
        }
        
        // 查看商品详情
        function viewProduct(productId) {
            window.open(`/product-review/page/product-detail?id=\${productId}`, '_blank');
        }
        
        // 删除商品
        function deleteProduct(productId) {
            if (confirm('确定要删除该商品吗？此操作不可恢复！')) {
                $.ajax({
                    url: `/product-review/product/\${productId}`,
                    type: 'DELETE',
                    success: function(result) {
                        if (result.code === 200) {
                            alert('商品删除成功');
                            loadProducts();
                        } else {
                            alert('删除失败：' + result.message);
                        }
                    },
                    error: function() {
                        alert('删除失败');
                    }
                });
            }
        }
        
        // 全选/取消全选
        function toggleSelectAll() {
            const selectAll = $('#selectAll').prop('checked');
            $('.product-checkbox').prop('checked', selectAll);
        }
        
        // 选择所有商品
        function selectAllProducts() {
            $('.product-checkbox').prop('checked', true);
            $('#selectAll').prop('checked', true);
        }
        
        // 批量删除商品
        function batchDeleteProducts() {
            const selectedIds = [];
            $('.product-checkbox:checked').each(function() {
                selectedIds.push(parseInt($(this).val()));
            });
            
            if (selectedIds.length === 0) {
                alert('请选择要删除的商品');
                return;
            }
            
            if (confirm(`确定要删除选中的 ${selectedIds.length} 个商品吗？此操作不可恢复！`)) {
                $.ajax({
                    url: '/product-review/product/batch',
                    type: 'DELETE',
                    contentType: 'application/json',
                    data: JSON.stringify(selectedIds),
                    success: function(result) {
                        if (result.code === 200) {
                            alert('批量删除成功');
                            loadProducts();
                            $('#selectAll').prop('checked', false);
                        } else {
                            alert('批量删除失败：' + result.message);
                        }
                    },
                    error: function() {
                        alert('批量删除失败');
                    }
                });
            }
        }
        
        // 刷新商品列表
        function refreshProducts() {
            loadProducts();
        }
        
        // 退出登录
        function logout() {
            $.ajax({
                url: '/product-review/user/logout',
                type: 'POST',
                success: function(result) {
                    if (result.code === 200) {
                        window.location.href = '/product-review/page/index';
                    } else {
                        alert('退出登录失败：' + result.message);
                    }
                },
                error: function() {
                    alert('退出登录失败');
                }
            });
        }
    </script>
</body>
</html>